home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7240 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mudskipper.cac.psu.edu!user
  2. From: fcusack@tdx.org (frank.)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: simple code, argc, argv, strcmp()
  5. Date: Fri, 16 Feb 1996 08:46:05 -0400
  6. Organization: Psychic Enemies Network
  7. Message-ID: <fcusack-1602960846050001@mudskipper.cac.psu.edu>
  8. References: <11f7cc$17261a.3b3@daprez> <4g1vl1$rm2@maverick.tad.eds.com>
  9. NNTP-Posting-Host: mudskipper.cac.psu.edu
  10.  
  11. In article <4g1vl1$rm2@maverick.tad.eds.com>, Ed McGuffey
  12. <fgae23@ods04.and.ifg.gmeds.com> wrote:
  13.  
  14. > If you really want to use the !, try:
  15. >  
  16. >    if (!((strcmp(argv[1], "-d") || (strcmp(argv[1], "-e"))) 
  17. >       Usage();
  18. > since you want the ! to apply to the entire expression consisting of the
  19. > two compares.  The code is more readable, however, to avoid negative logic
  20. > altogether and just say:
  21. >    if ((strcmp(argv[1], "-d") || (strcmp(argv[1], "-e")) 
  22. >       function();
  23. >    else
  24. >       Usage();
  25.  
  26. Let's see what would happen if argv[1] == "-d"
  27.  
  28. if ( <zero> || <non-zero> )   /* evaluates to true, OK */
  29.  
  30. The same would happen for argv[1] == "-e".
  31.  
  32. Let's see what happens if argv[1] == "-k"
  33.  
  34. if ( <non-zero> || <short-circuit, not evaluated> ) /* evals to true, not OK */
  35.  
  36. Oh well.
  37. ~Frank
  38.  -- I am Pentium of Borg.  Division is futile.  You will be approximated. --
  39.  --   If you build it, they will come --> http://www.tdx.org/~fcusack/    --
  40.  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B 0F F9 EA --
  41.